package integral_type

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type IntegralType int

const (
	Main IntegralType = iota + 1
	QingNiao
)

func (e IntegralType) Code() int32 {
	return int32(e)
}

func (e IntegralType) Des() string {
	return enums.BE(e).Des
}

func (e IntegralType) Enum() string {
	return enums.BE(e).Enum
}

func (e IntegralType) Val() int {
	return int(e)
}

func (e *IntegralType) UnmarshalJSON(value []byte) error {
	*e = IntegralType(enums.UnmarshalEnum(value))
	return nil
}

func (e IntegralType) MarshalJSON() ([]byte, error) {
	switch e {
	case Main:
		return enums.JsonObj(int(e), "Main", "主要")
	case QingNiao:
		return enums.JsonObj(int(e), "QingNiao", "青鸟送信")
	}
	return []byte(strconv.Itoa(int(e))), nil
}
